<?php
namespace App\Http\Controllers\SysAdmin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use App\Models\User;
use App\Models\RegUser;
use App\Models\Register;
use App\Models\Company;

class BaseController extends Controller
{
    protected $corpid;
    protected $user;
    
    public function __construct()
    {
        if(empty(Auth::user())){
            abort(403,'登录信息错误');
        }
        $user = Auth::user()->comuser();
        if(!empty($user)){
            $this->user = $user;
        }else{
           abort(403,'登录信息错误');
        }
        if(empty($this->user)){
            abort(403,'用户信息有误');
        }
        $this->corpid = $this->user->corpid;
        if(empty($this->corpid)){
            abort(403,'企业信息有错误');
        }
        $com = Company::where('id',$this->user->corpid)->first();
        if(empty($com)){
            //abort(403,'企业未完成初始化');
        }else{
            if($com->init_index != 2){
                if($_SERVER['REQUEST_URI'] != '/sysadmin/feedback/init' && str_contains('/sysadmin/feedback/init-feedback',$_SERVER['REQUEST_URI']) ){
                    abort(403,"企业月度意见名称未填写完成");
                }
            }
        }
    }
    

    public function formatJson($status='200',$msg='没有更多数据',$data=array(),$redirectUrl = '')
    {
        $result = array(
            'status'        => $status,
            'msg'           => $msg,
            'data'          => $data,
            'redirectUrl'   => $redirectUrl
        );
        return Response::json($result);
    }
    
   
}

